﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsCatcher
    {
        public int Check(int ServerID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CollectingNum", SqlDbType.Int, 4), new SqlParameter("@ServerID", SqlDbType.Int, 4) };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = ServerID;
            DbHelperSQL.RunProcedure("CmsCatcher_Check", parameters, out num);
            return (int) parameters[0].Value;
        }

        public KeRui.Model.CmsCatch GetModel(int ServerID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ServerID", SqlDbType.Int, 4) };
            parameters[0].Value = ServerID;
            KeRui.Model.CmsCatch @catch = new KeRui.Model.CmsCatch();
            DataSet set = DbHelperSQL.RunProcedure("CmsCatcher_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["CatchID"].ToString() != "")
                {
                    @catch.CatchID = int.Parse(set.Tables[0].Rows[0]["CatchID"].ToString());
                }
                @catch.CatchName = set.Tables[0].Rows[0]["CatchName"].ToString();
                if (set.Tables[0].Rows[0]["IsUsing"].ToString() != "")
                {
                    @catch.IsUsing = int.Parse(set.Tables[0].Rows[0]["IsUsing"].ToString());
                }
                @catch.Url = set.Tables[0].Rows[0]["Url"].ToString();
                if (set.Tables[0].Rows[0]["StartPage"].ToString() != "")
                {
                    @catch.StartPage = int.Parse(set.Tables[0].Rows[0]["StartPage"].ToString());
                }
                if (set.Tables[0].Rows[0]["EndPage"].ToString() != "")
                {
                    @catch.EndPage = int.Parse(set.Tables[0].Rows[0]["EndPage"].ToString());
                }
                if (set.Tables[0].Rows[0]["CurPage"].ToString() != "")
                {
                    @catch.CurPage = int.Parse(set.Tables[0].Rows[0]["CurPage"].ToString());
                }
                if (set.Tables[0].Rows[0]["Interval"].ToString() != "")
                {
                    @catch.Interval = int.Parse(set.Tables[0].Rows[0]["Interval"].ToString());
                }
                if (set.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    @catch.State = int.Parse(set.Tables[0].Rows[0]["State"].ToString());
                }
                if (set.Tables[0].Rows[0]["LastTime"].ToString() != "")
                {
                    @catch.LastTime = DateTime.Parse(set.Tables[0].Rows[0]["LastTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["CurTimes"].ToString() != "")
                {
                    @catch.CurTimes = int.Parse(set.Tables[0].Rows[0]["CurTimes"].ToString());
                }
                if (set.Tables[0].Rows[0]["AllTimes"].ToString() != "")
                {
                    @catch.AllTimes = int.Parse(set.Tables[0].Rows[0]["AllTimes"].ToString());
                }
                if (set.Tables[0].Rows[0]["NodeID"].ToString() != "")
                {
                    @catch.NodeID = int.Parse(set.Tables[0].Rows[0]["NodeID"].ToString());
                }
                @catch.NodeName = set.Tables[0].Rows[0]["NodeName"].ToString();
                if (set.Tables[0].Rows[0]["SiteID"].ToString() != "")
                {
                    @catch.SiteID = int.Parse(set.Tables[0].Rows[0]["SiteID"].ToString());
                }
                if (set.Tables[0].Rows[0]["ServerID"].ToString() != "")
                {
                    @catch.ServerID = int.Parse(set.Tables[0].Rows[0]["ServerID"].ToString());
                }
                @catch.Whilelist = set.Tables[0].Rows[0]["Whilelist"].ToString();
                @catch.Blacklist = set.Tables[0].Rows[0]["Blacklist"].ToString();
                @catch.ContentPlus = set.Tables[0].Rows[0]["ContentPlus"].ToString();
                if (set.Tables[0].Rows[0]["SavePic"].ToString() != "")
                {
                    @catch.SavePic = int.Parse(set.Tables[0].Rows[0]["SavePic"].ToString());
                }
                if (set.Tables[0].Rows[0]["ContentType"].ToString() != "")
                {
                    @catch.ContentType = int.Parse(set.Tables[0].Rows[0]["ContentType"].ToString());
                }
                if (set.Tables[0].Rows[0]["ParseID"].ToString() != "")
                {
                    @catch.ParseID = int.Parse(set.Tables[0].Rows[0]["ParseID"].ToString());
                }
                @catch.ParseName = set.Tables[0].Rows[0]["ParseName"].ToString();
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    @catch.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    @catch.UpdateTime = DateTime.Parse(set.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                return @catch;
            }
            return null;
        }

        public void Init(int ServerID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ServerID", SqlDbType.Int, 4) };
            parameters[0].Value = ServerID;
            DbHelperSQL.RunProcedure("CmsCatcher_Init", parameters, "ds");
        }

        public void Repair(int ServerID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ServerID", SqlDbType.Int, 4) };
            parameters[0].Value = ServerID;
            DbHelperSQL.RunProcedure("CmsCatcher_Repair", parameters, "ds");
        }

        public void Update(int CatchID, int State)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.Int, 4) };
            parameters[0].Value = CatchID;
            parameters[1].Value = State;
            DbHelperSQL.RunProcedure("CmsCatcher_Update", parameters, out num);
        }

        public void UpdateError(int CatchID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4) };
            parameters[0].Value = CatchID;
            DbHelperSQL.RunProcedure("CmsCatcher_UpdateError", parameters, out num);
        }

        public void UpdatePage(int CatchID, int CurPage)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4), new SqlParameter("@CurPage", SqlDbType.Int, 4) };
            parameters[0].Value = CatchID;
            parameters[1].Value = CurPage;
            DbHelperSQL.RunProcedure("CmsCatcher_UpdatePage", parameters, out num);
        }

        public void UpdateUsing(int CatchID, int IsUsing)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4), new SqlParameter("@IsUsing", SqlDbType.Int, 4) };
            parameters[0].Value = CatchID;
            parameters[1].Value = IsUsing;
            DbHelperSQL.RunProcedure("CmsCatcher_UpdateUsing", parameters, out num);
        }
    }
}

